---
title: "Width"
description: "Utilities for setting the width of an element"
features:
  responsive: true
  customizable: true
  hover: false
  focus: false
---

import plugin from 'tailwindcss/lib/plugins/width'
import { Variants } from '@/components/Variants'
import { Disabling } from '@/components/Disabling'
import { numbersFirst } from '@/utils/sortClasses'

export const classes = {
  plugin,
  sort: numbersFirst,
}

## Auto

Use `w-auto` to let the browser calculate and select the width for the element. You can use it to unset a specific width:

```html
<div class="w-24 **md:w-auto** ..."></div>
```

## Screen Width

Use `w-screen` to make an element span the entire width of the viewport.

```html
<div class="h-12 **w-screen**"></div>
```

## Fixed Width

Use `w-{number}` or `w-px` to set an element to a fixed width.


```html lightBlue
<template preview>
  <div class="flex flex-col space-y-8 mx-auto w-64">
    <div class="flex items-center space-x-4">
      <p class="text-sm text-light-blue-600 w-12 text-right">w-8</p>
      <div class="h-8 w-8 rounded-md bg-light-blue-500 text-white text-2xl font-extrabold"></div>
    </div>
    <div class="flex items-center space-x-4">
      <p class="text-sm text-light-blue-600 w-12 text-right">w-12</p>
      <div class="h-8 w-12 rounded-md bg-light-blue-500 text-white text-2xl font-extrabold"></div>
    </div>
    <div class="flex items-center space-x-4">
      <p class="text-sm text-light-blue-600 w-12 text-right">w-16</p>
      <div class="h-8 w-16 rounded-md bg-light-blue-500 text-white text-2xl font-extrabold"></div>
    </div>
    <div class="flex items-center space-x-4">
      <p class="text-sm text-light-blue-600 w-12 text-right">w-24</p>
      <div class="h-8 w-24 rounded-md bg-light-blue-500 text-white text-2xl font-extrabold"></div>
    </div>
  </div>
</template>

<div>
  <div class="**w-8** ..."></div>
  <div class="**w-12** ..."></div>
  <div class="**w-16** ..."></div>
  <div class="**w-24** ..."></div>
</div>
```

## Fluid Width

Use `w-{fraction}` or `w-full` to set an element to a percentage based width.

```html rose
<template preview>
  <div class="space-y-6">
    <div class="flex rounded-md overflow-hidden text-white font-mono">
      <div class="w-1/2 px-2 py-4 bg-rose-400 text-center">w-1/2</div>
      <div class="w-1/2 px-2 py-4 bg-rose-500 text-center">w-1/2</div>
    </div>
    <div class="flex rounded-md overflow-hidden text-white font-mono">
      <div class="w-2/5 px-2 py-4 bg-rose-400 text-center">w-2/5</div>
      <div class="w-3/5 px-2 py-4 bg-rose-500 text-center">w-3/5</div>
    </div>
    <div class="flex rounded-md overflow-hidden text-white font-mono">
      <div class="w-1/3 px-2 py-4 bg-rose-400 text-center">w-1/3</div>
      <div class="w-2/3 px-2 py-4 bg-rose-500 text-center">w-2/3</div>
    </div>
    <div class="flex rounded-md overflow-hidden text-white font-mono">
      <div class="w-1/4 px-2 py-4 bg-rose-400 text-center">w-1/4</div>
      <div class="w-3/4 px-2 py-4 bg-rose-500 text-center">w-3/4</div>
    </div>
    <div class="flex rounded-md overflow-hidden text-white font-mono">
      <div class="w-1/5 px-2 py-4 bg-rose-400 text-center">w-1/5</div>
      <div class="w-4/5 px-2 py-4 bg-rose-500 text-center">w-4/5</div>
    </div>
    <div class="flex rounded-md overflow-hidden text-white font-mono">
      <div class="w-1/6 px-2 py-4 bg-rose-400 text-center">w-1/6</div>
      <div class="w-5/6 px-2 py-4 bg-rose-500 text-center">w-5/6</div>
    </div>
    <div class="rounded-md w-full px-2 py-4 bg-rose-500 text-center text-white font-mono">w-full</div>
  </div>
</template>


<div class="flex ...">
  <div class="**w-1/2** ... ">w-1/2</div>
  <div class="**w-1/2** ... ">w-1/2</div>
</div>
<div class="flex ...">
  <div class="**w-2/5** ...">w-2/5</div>
  <div class="**w-3/5** ...">w-3/5</div>
</div>
<div class="flex ...">
  <div class="**w-1/3** ...">w-1/3</div>
  <div class="**w-2/3** ...">w-2/3</div>
</div>
<div class="flex ...">
  <div class="**w-1/4** ...">w-1/4</div>
  <div class="**w-3/4** ...">w-3/4</div>
</div>
<div class="flex ...">
  <div class="**w-1/5** ...">w-1/5</div>
  <div class="**w-4/5** ...">w-4/5</div>
</div>
<div class="flex ...">
  <div class="**w-1/6** ...">w-1/6</div>
  <div class="**w-5/6** ...">w-5/6</div>
</div>
<div class="**w-full** ...">w-full</div>
```

## Responsive

To control the width of an element at a specific breakpoint, add a `{screen}:` prefix to any existing width utility. For example, adding the class `md:w-full` to an element would apply the `w-full` utility at medium screen sizes and above.

```html
<div class="w-1/2 **md:w-full** ...">
  <!-- ... -->
</div>
```

For more information about Tailwind's responsive design features, check out the [Responsive Design](/docs/responsive-design) documentation.

## Customizing

### Width scale

By default, Tailwind's width scale is a combination of the [default spacing scale](/docs/customizing-spacing#default-spacing-scale) as well as some additional values specific to widths.

You can customize the spacing scale for padding, margin, width, and height all at once in the `theme.spacing` or `theme.extend.spacing` sections of your `tailwind.config.js` file:

```diff-js
  // tailwind.config.js
  module.exports = {
    theme: {
      extend: {
+       spacing: {
+         '72': '18rem',
+         '84': '21rem',
+         '96': '24rem',
+       }
      }
    }
  }
```

To customize width separately, use the `theme.width` section of your `tailwind.config.js` file.

```diff-js
  // tailwind.config.js
  module.exports = {
    theme: {
      extend: {
+       width: {
+         '1/7': '14.2857143%',
+         '2/7': '28.5714286%',
+         '3/7': '42.8571429%',
+         '4/7': '57.1428571%',
+         '5/7': '71.4285714%',
+         '6/7': '85.7142857%',
+       }
      }
    }
  }
```

Learn more about customizing the default theme in the [theme customization documentation](/docs/theme#customizing-the-default-theme).

### Variants

<Variants plugin="width" />

### Disabling

<Disabling plugin="width" />
